﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Drawing;
using System.Runtime.InteropServices;   //使用DllImport
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace KMouse
{
    public partial class Func
    {
        [DllImport("user32.dll")]
        static extern bool GetCursorInfo(out CURSORINFO pci);
        private const Int32 CURSOR_SHOWING = 0x00000001;

        [StructLayout(LayoutKind.Sequential)]
        struct POINT
        {
            public Int32 x;
            public Int32 y;
        }
        [StructLayout(LayoutKind.Sequential)]
        struct CURSORINFO
        {
            public Int32 cbSize;
            public Int32 flags;
            public IntPtr hCursor;
            public POINT ptScreenPos;
        }

        //获得当前鼠标的位置
        public static Cursor GetCursor(out int x, out int y)
        {
            //画出鼠标
            CURSORINFO pci;
            pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
            GetCursorInfo(out pci);
            Cursor cur;
            try
            {
                cur = new Cursor(pci.hCursor);
            }
            catch
            {
                cur = null;
                //Dbg.WriteLine("#Cal curur fail!");
            }

            x = pci.ptScreenPos.x;
            y = pci.ptScreenPos.y;

            return cur;
        }
    }
}
